//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    searchText: '',
    userInfo: {},
    hasUserInfo: false,
    gifts: [],
    topics: [], // 专题数据
    userRecommendRepastInfo: {} // 用户最后一条论坛信息
  },
  //搜索框输入事件处理函数
  bindSearchInput: function (event) {
    console.log(this);
    this.setData({
      searchText: event.detail.value
    });
  },
  onLoad: function () {
    if (app.globalData.userInfo) {
      this.setData({
        userInfo: app.globalData.userInfo,
        hasUserInfo: true
      })
    } else {
      // 在没有 open-type=getUserInfo 版本的兼容处理
      wx.getUserInfo({
        success: res => {
          app.globalData.userInfo = res.userInfo
          this.setData({
            userInfo: res.userInfo,
            hasUserInfo: true
          })
        }
      })
    }
    this.getUserLastRepastInfo();
    this.getTopics();
    this.getGifts();
  },
  getUserInfo: function (e) {
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  },
  getUserLastRepastInfo: function () {
    this.setData({
      userRecommendRepastInfo: {
        labelName: '轻餐论坛',
        title: '#餐饮达人#餐饮做不大的解决办法是什么？',
        depict: '餐饮人一直面临很大的困局要域特别难为何……',
        images: ['../../images/index/photo01.jpg', '../../images/index/photo02.jpg', '../../images/index/photo03.jpg'],
        laud: 300,
        collect: 50,
        msg: 325,
        gold: 50
      }
    });
  },
  getTopics: function () {
    this.setData({
      topics: [{
        avatarUrl: '../../images/index/pic_img.jpg',
        nickName: '一绝道长',
        levelIcon: '../../images/index/icon03.png',
        labelName: '轻餐论坛',
        title: '#餐饮达人#餐饮做不大的解决办法是什么？',
        depict: '餐饮人一直面临很大的困局要域特别难为何……',
        laud: 300,
        collect: 50,
        msg: 325,
        gold: 50
      }, {
        avatarUrl: '../../images/index/pic_img.jpg',
        nickName: '二绝道长',
        levelIcon: '../../images/index/icon03.png',
        labelName: '轻餐论坛',
        title: '#餐饮达人#餐饮做不大的解决办法是什么？',
        depict: '餐饮人一直面临很大的困局要域特别难为何……',
        laud: 300,
        collect: 50,
        msg: 325,
        gold: 50
      }, {
        avatarUrl: '../../images/index/pic_img.jpg',
        nickName: '二绝道长',
        levelIcon: '../../images/index/icon03.png',
        labelName: '轻餐论坛',
        title: '#餐饮达人#餐饮做不大的解决办法是什么？',
        depict: '餐饮人一直面临很大的困局要域特别难为何……',
        laud: 300,
        collect: 50,
        msg: 325,
        gold: 50
      }]
    });
  },
  getGifts: function () {
    this.setData({
      gifts: [{
        icon: '../../images/index/img07.png',
        num: 200
      }, {
        icon: '../../images/index/img08.png',
        num: 300
      }, {
        icon: '../../images/index/img09.png',
        num: 400
      }]
    });
  },
  showInfo: function (event) {
    wx.navigateTo({
      url: '../details/details'
    })
  }
})
